<template>
	<hyb-page :title="yg_title">
		<template v-slot:body>
			<form @submit="submit">
				<view class="gui-bg-white gui-dark-bg-level-3 ">
					<view class="gui-form-item gui-border-b gui-padding">
						<text class="gui-form-label gui-secondary-text">用户uid</text>
						<view class="gui-form-body" @tap="chooseSj()">
							<input type="text" style="pointer-events: none;" class="gui-form-input" v-model="formData.u_id"
								placeholder="请选择用户uid" />
						</view>

						<view @tap="chooseSj()" class="gui-icons gui-color-gray">&#xe601;</view>
					</view>

					<view class="gui-form-item gui-border-b gui-padding">
						<text class="gui-form-label gui-secondary-text">商家名称</text>
						<view class="gui-form-body">
							<input type="text" class="gui-form-input" v-model="formData.s_name" placeholder="商家名称" />
						</view>
					</view>


					<view class="gui-form-item gui-border-b gui-padding">
						<text class="gui-form-label gui-secondary-text">商家图片</text>
						<view class="gui-form-body gui-flex">
							<hyb-upload ref="s_thumb" v-model="formData.s_thumb"></hyb-upload>
						</view>
					</view>



					<view class="gui-form-item gui-border-b gui-padding">
						<text class="gui-form-label gui-secondary-text">联系电话</text>
						<view class="gui-form-body">
							<!-- <hyb-phone v-model="formData.y_telphone"></hyb-phone> -->
							<input type="text" class="gui-form-input" v-model="formData.s_telphone"
								placeholder="请输入电话号码" />
						</view>
					</view>

					<view class="gui-form-item gui-border-b gui-padding">
						<text class="gui-form-label gui-secondary-text">商家位置</text>
						<view class="gui-form-body">
							<hyb-city @change="addressChange" tag="1" v-model="formData.s_address"></hyb-city>
						</view>
					</view>
					<!-- <view class="gui-form-item gui-border-b gui-padding">
						<text class="gui-form-label gui-secondary-text">详细地址：</text>
						<view class="gui-form-body">
							<input type="text" class="gui-form-input" v-model="formData.s_xxaddress"
								placeholder="请输入详细地址" />
						</view>
					</view> -->


					<view class="gui-form-item gui-border-b gui-padding">
						<text class="gui-form-label gui-secondary-text">商户号：</text>
						<view class="gui-form-body">
							<input type="text" class="gui-form-input" v-model="formData.wx_pay.mch_id"
								placeholder="请输入商户号" />
						</view>
					</view>


					<view class="gui-form-item gui-border-b gui-padding">
						<text class="gui-form-label gui-secondary-text">商户秘钥Key：</text>
						<view class="gui-form-body">
							<input type="text" class="gui-form-input" v-model="formData.wx_pay.mch_secret_key"
								placeholder="商户秘钥Key" />
						</view>
					</view>


					<view class="gui-form-item gui-border-b gui-padding">
						<text class="gui-form-label gui-secondary-text">私钥apiclient_key：</text>
						<view class="gui-form-body">
							<textarea maxlength="-1" type="textarea" class="gui-textarea"
								v-model="formData.wx_pay.mch_secret_cert" placeholder="请输入私钥apiclient_key" />
						</view>
					</view>


					<view class="gui-form-item gui-border-b gui-padding">
						<text class="gui-form-label gui-secondary-text">公钥apiclient_cer：</text>
						<view class="gui-form-body">
							<textarea maxlength="-1" type="textarea" class="gui-textarea"
								v-model="formData.wx_pay.mch_public_cert" placeholder="公钥apiclient_cer" />
						</view>
					</view>
                    
					<view class="gui-form-item gui-border-b gui-padding">
						<text class="gui-form-label gui-secondary-text">微信公钥：</text>
						<view class="gui-form-body">
							<textarea maxlength="-1" type="textarea" class="gui-textarea"
								v-model="formData.wx_pay.wx_public_cert" placeholder="微信公钥" />
						</view>
					</view>


					<view class="gui-form-item gui-border-b gui-padding">
						<text class="gui-form-label gui-secondary-text">证书序列号：</text>
						<view class="gui-form-body">
							<input type="text" class="gui-form-input" v-model="formData.wx_pay.serial_no"
								placeholder="请输入详细地址" />
						</view>
					</view>


					<view class="gui-form-item gui-border-b gui-padding">
						<text class="gui-form-label gui-secondary-text">小程序应用appid：</text>
						<view class="gui-form-body">
							<input type="text" class="gui-form-input" v-model="formData.wx_pay.mini_app_id"
								placeholder="小程序应用appid" />
						</view>
					</view>





					<view class="gui-bg-white gui-dark-bg-level-3 gui-padding gui-margin-top">
						<button type="default" class="gui-button gui-bg-primary gui-noborder" @tap="confirm"
							style="border-radius:50rpx;">
							<text class="gui-color-white gui-button-text">保存</text>
						</button>
					</view>
				</view>
			</form>

			<view style="height: 100rpx;"></view>
		</template>
	</hyb-page>

</template>

<script>
	import graceChecker from "@/Grace6/js/checker.js";
	import parserHtml from "@/Grace6/js/parserHTML.js";
	export default {
		data() {
			return {
				formData: {
					wx_pay: {}
				},
				rule: [{
					name: "s_name",
					checkType: "string",
					checkRule: "2,10",
					errorMsg: "姓名应为2-10个字符"
				}, ],
			}
		},

		onLoad(options) {
			console.log(options.id)
			if (options.id) {
				uni.gPost("shangjia/info", {
					s_id: options.id
				}).then((info) => {
					if (!info.wx_pay) {
						info.wx_pay = {}
					}
					this.formData = info;
					console.log(this.formData)
				})
			}
		},

		computed: {
			base: () => {
				return uni.storage.get("base");
			}
		},

		created() {

		},
		methods: {
			chooseSj() {
				uni.$once("choose_user", (data) => {
					this.formData.u_id = data.u_id
				})
				// uni.navigateTo({
				// 	url: '/hyb_o2o/user/list/list?tag=1'
				// })
			},
			addressChange(e) {
				console.log(e)
				this.formData.s_address = e.address
				this.formData.latitude = e.latitude
				this.formData.longitude = e.longitude
			},

			async confirm() {

				let that = this;

				uni.showLoading({
					title: "提交中..."
				})

				if (that.$refs.s_thumb) {
					await that.$refs.s_thumb.uploadAsync()
				}

				console.log(that.formData)

				let checkRes = graceChecker.check(that.formData, that.rule);
				if (checkRes) {
					this.formData.tag = 'manage'
					uni.gPost("shangjia/save", that.formData).then((res) => {
						uni.hideLoading();
						uni.showToast({
							title: "提交成功",
						});
					})
				} else {
					uni.hideLoading();
					uni.showToast({
						title: graceChecker.error,
						icon: "none"
					});
				}
			},
		}
	}
</script>

<style>
	.gui-form-label {
		width: 160rpx;
	}

	.modal-btns {
		line-height: 100rpx;
		height: 100rpx;
		font-size: 35rpx;
		text-align: center;
		width: 320rpx;
	}
</style>
